import { PerspectiveCamera, WebGLRenderer } from "three";
import { Size } from "./size";

/**
 * 处理窗口大小改变事件
 * 更新相机和渲染器的尺寸
 */
export const onWindowResize =
  (camera: PerspectiveCamera, renderer: WebGLRenderer) => () => {
    const width = window.innerWidth;
    const height = window.innerHeight;

    camera.aspect = Size.aspect;
    camera.updateProjectionMatrix();

    renderer.setSize(width, height);
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
  };
